package org.xutils.main.vm;


import android.app.Application;

import com.zzh.lib.core.utils.LogUtils;
import com.zzh.mvvm.base.vm.BaseViewModel;
import com.zzh.mvvm.binding.command.BindingCommand;

import org.xutils.db.ex.DbException;
import org.xutils.main.App;
import org.xutils.main.DemoModel;
import org.xutils.main.UserModel;
import org.xutils.main.ds.DbModel;

import java.util.List;

/**
 * Created by zzh on 2023/11/13.
 *
 * @date: 2023/11/13 14:14
 * @email: zzh_hz@126.com
 * @author: zzh
 * @description: org.xutils.main.vm
 */
public class DbViewModel extends BaseViewModel<DbModel> {
    public DbViewModel(Application application) {
        super(application);
    }

    public BindingCommand clickInsertData2Db = new BindingCommand(() -> {

        DemoModel model = new DemoModel();
        model.setAge(2).setExtra("这是一个扩展数据").setTargetId("10001").setUserName("张三");
        try {
            App.getInstance().getDbManager().saveOrUpdate(model);
        } catch (DbException e) {
            throw new RuntimeException(e);
        }

    });
    public BindingCommand clickQueryData2Db = new BindingCommand(() -> {

        try {
            List<DemoModel> all = App.getInstance().getDbManager().findAll(DemoModel.class);
            LogUtils.d("---------数据：" + all.size());
        } catch (DbException e) {
            throw new RuntimeException(e);
        }

    });
}
